<?php
class Default_Model_Warehouse
{

	private $_table;
	//Initalizing Db Table
	public function __construct(){
		$this->_table = new Default_Model_DbTable_Warehouse();
	}


	/**
	*Create A Record
	*@param rowSet $row warehouse's data
	*@return boolean
	*/
	public  function add($row){
 		return $this->_table->insert($row);
	}

	/**
	*Update One Row
	*@param rowSet $row warehouse's data
	*@param int $wh_id
	*@return boolean
	*/
	public  function update($row,$id){

		$where = $this->_table->getAdapter()->quoteInto("warehouse_id= ?", $id);

		return $this->_table->update($row, $where);

	}

	/**
	*Delete One Row
	*@param int $wh_id
	*@return boolean
	*/
	public function delete($id){

		$where = $this->_table->getAdapter()->quoteInto("warehouse_id= ?", $id);

		return $this->_table->delete($where);

	}

    public function getByCondition($condition=array(),$type='*',$orderby="warehouse_id",$pageSize=0,$page=1){
        $select = $this->_table->getAdapter()->select();
        $table = $this->_table->info('name');
        $select->from($table,$type);
        $select->where("1 =?",1);
		if(isset($condition["warehouse_name"]) && $condition["warehouse_name"]!=''){
            $select->where(" warehouse_name like ?","%".$condition["warehouse_name"]."%");
            $select->orWhere(" warehouse_desc like ?","%".$condition["warehouse_name"]."%");
        }
        if('count(*)'==$type){
            return $this->_table->getAdapter()->fetchOne($select);
        }else{
            $select->order($orderby);
            if($pageSize>0 and $page>0)
            {
                $start =($page-1)*$pageSize;
                $select->limit($pageSize,$start);
            }
			$sql=$select->__toString();

		    return $this->_table->getAdapter()->fetchAll($sql);
        }

	}

	/**
	*Get Rowset By warehouse
	*@param string $warehouse_id
	*@return Rowset
	*/
	public function getById($id){
		$where = $this->_table->getAdapter()->quoteInto('warehouse_id= ?', $id);
		return $this->_table->fetchRow($where);
	}

	public function getByfield($field=1,$value=1){
		$where = $this->_table->getAdapter()->quoteInto("{$field} = ?",$value);
		return $this->_table->fetchAll($where);
	}


}